home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 52
/
Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso
/
Aminet
/
dev
/
lang
/
AmigaTalk.lha
/
general
/
Interval.st
< prev
next >
Wrap
Text File
|
2000-05-15
|
2KB
|
63 lines
Class Interval :SequenceableCollection
! lower upper step current !
[
from: lowerBound to: upperBound by: stepSize
current <- lower <- lowerBound.
upper <- upperBound.
step <- stepSize
|
size
^ ((step strictlyPositive)
ifTrue: [upper < lower]
ifFalse: [lower < upper] )
ifTrue: [ 0 ]
ifFalse: [upper - lower // step + 1]
|
inRange: value
^ (step strictlyPositive)
ifTrue: [(value >= lower) and: [value <= upper]]
ifFalse: [(value >= upper) and: [value <= lower]]
|
first
current <- lower.
^ (self inRange: current) ifTrue: [current]
|
last
current <- upper.
^ (self inRange: current) ifTrue: [current]
|
next
current <- current + step.
^ (self inRange: current) ifTrue: [current]
|
at: index ifAbsent: exceptionBlock ! val !
val <- lower + (step * (index - 1)).
^ (self inRange: val)
ifTrue: [ val ]
ifFalse: [exceptionBlock value]
|
printString
^ 'Interval ', lower printString , ' to ',
upper printString , ' by ' , step printString
|
coerce: newcollection
^ newcollection asArray
|
at: index put: val
^ self error: 'cannot store into Interval'
|
add: val
^ self error: 'cannot store into Interval'
|
removeKey: key ifAbsent: exceptionBlock
self error: 'cannot remove from Interval'.
^ exceptionBlock value
|
deepCopy
^ lower to: upper by: step
|
shallowCopy
^ lower to: upper by: step
]